import http.server
import socketserver
import os

# 设置服务器端口
PORT = 8000

# 获取当前目录
current_dir = os.path.dirname(os.path.abspath(__file__))

# 更改工作目录到当前脚本所在目录
os.chdir(current_dir)

# 创建HTTP请求处理器
Handler = http.server.SimpleHTTPRequestHandler

# 创建TCP服务器
with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print(f"Serving HTTP on port {PORT}")
    print(f"Open your browser and visit http://localhost:{PORT}/werewolf.html")
    try:
        # 启动服务器
        httpd.serve_forever()
    except KeyboardInterrupt:
        # 处理Ctrl+C中断
        print("\nStopping server...")
        httpd.server_close()
        print("Server stopped.")